<div class="row">
    <div class="col-lg-12">
        <h3 class="page-header">Danh sách tin tức</h3>
    </div>
    <!-- /.col-lg-12 -->
</div>
<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default">            
            <div class="panel-heading">
                <div class="row">
                    <div class="col-lg-3">
                        <a class="" href="<?php echo $this->url(array("action"=>"add")) ?>">Thêm tin tức mới</a>
                    </div>
                    <a href="list.phtml"></a>
                </div>
            </div>
            <div class="panel-body">
                <div class="table-reponsive">
                    <div id="jqxgrid">

                    </div>
                </div>
            </div>
    </div>
</div>
<script type="text/javascript">
        $(document).ready(function () {
            // prepare the data
            var source =
            {
                datatype: "json",
                datafields:
                [
                    { name: 'id',type:'int'},
                    { name: 'title', type: 'string' },                    
                    { name: 'description', type: 'string' },
                    { name: 'news_cat_name', type : 'string'},
                    { name: 'event', type: 'bool' },
                    { name: 'status', type: 'bool' }                   
                ],
                url:'<?php echo $this->baseUrl() ?>/admin/news/service',
                sortcolumn: 'id',
                sortdirection: 'asc'
               
            };
         var dataAdapter = new $.jqx.dataAdapter(source, {
                loadComplete: function () {
                }
            });
            $("#jqxgrid").jqxGrid(
            {
                width: '100%',
                source: dataAdapter,  
                theme: 'bootstrap',
                pageable: true,
                showfilterrow: true,
                filterable: true,
                autoheight: true,
                sortable: true,
                altrows: true,
                enabletooltips: true,
                selectionmode: 'multiplecellsadvanced',
                columnsResize: true,
                rendergridrows: function (params) {
                    return params.data;
                },
                ready: function () {
                    $("#jqxgrid").jqxGrid('hideColumn', 'id');
                },
                columns: [
                  {text:'id',dataField:'id',cellsalgin:'right',width:0},
                  { text: 'Tiêu đề',editable: false, dataField: 'title', width: '25%' },
                  { text: 'Mô tả', editable: false, dataField: 'description', width: '30%' },                  
                  { text: 'Nhóm người xem', editable: false, dataField: 'news_cat_name', width: '15%' },                  
                  { text: 'Sự kiện',columnType:'checkbox', editable: false, dataField: 'event', width: '10%' },
                  { text: 'Hiển thị',columnType:'checkbox', editable: false, dataField: 'status', width: '10%' },
                  {text: 'Xóa',width:'5%',filtertype: 'none', cellsalign: 'right', align: "center", columnType: 'none', editable: false, sortable: false, dataField: null, cellsrenderer: function (row) {
                          // render custom column.
                          editrow = row;
                          var dataRecord = $("#jqxgrid").jqxGrid('getrowdata',editrow);
                          var url= "<div style='overflow: hidden; text-overflow: ellipsis; padding-bottom: 2px; text-align: center; margin-right: 2px; margin-left: 4px; margin-top: 4px;'><a class='fa fa-trash-o fa-lg'";
                          url = url + "href='#' onclick='return jsdelete("+dataRecord.id+")'></a></div>"
                          return url;
                      }
              },
                {text: 'Sửa',width:'5%',filtertype: 'none', cellsalign: 'right', align: "center", columnType: 'none', editable: false, sortable: false, dataField: null, cellsrenderer: function (row) {
                          // render custom column.
                          editrow = row;
                          var dataRecord = $("#jqxgrid").jqxGrid('getrowdata',editrow);
                          var url= "<div style='overflow: hidden; text-overflow: ellipsis; padding-bottom: 2px; text-align: center; margin-right: 2px; margin-left: 4px; margin-top: 4px;'><a class='fa fa-edit fa-lg'";
                          url = url + "href='<?php echo $this->baseUrl() ?>/admin/news/edit/id/"+dataRecord.id+"'></a></div>"
                          return url;
                      }
                          }
                ]
            });
           
        });
    </script>
    <script type="text/javascript">
        function jsdelete(id)
        {            
                    bootbox.confirm("Bạn có chắc muốn xoá tin tức này không?",
                    function(result){
                        if(result == true)
                        {
                           return window.location = "<?php echo $this->baseUrl() ?>/admin/news/delete/id/"+id;
                        }
                    });             
        }
    </script>